package com.kate.mall.bff.wx.controller;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/30 22:08
 */

import cn.hutool.core.util.ObjectUtil;
import com.kate.mall.bff.wx.controller.form.SubmitOrderFrom;
import com.kate.mall.bff.wx.service.OrderService;
import com.kate.mall.common.annotation.LoginUser;
import com.kate.mall.common.utils.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 微信小程序订单api
 * @Auther: 新梦想*陈超
 * @Date: 2021/8/18 23:15
 */
@RestController
@RequestMapping("/wx/order")
public class OrderController {

    /**
     * 提交订单
     * {
     * 	"addressId": 4,
     * 	"cartId": 13,
     * 	"couponId": 3,
     * 	"grouponLinkId": 0,
     * 	"grouponRulesId": 0,
     * 	"message": ""
     * 	"userCouponId": 6
     * }
     */
    @Resource
    private OrderService orderService;
    @PostMapping("/submit")
    public R submitOrder(@LoginUser Integer userId, @RequestBody SubmitOrderFrom orderFrom) throws Exception {
        //TODO 1.是否登录
//        userId = 4;
        if(ObjectUtil.isEmpty(userId)){
            return R.badArgument();
        }
        //TODO 2.是否带参数
        if(ObjectUtil.isEmpty(orderFrom)){
            return R.badArgument();
        }
        R r = orderService.createOrder(orderFrom);
        return r;
    }

    @PostMapping("/prepay")
    public R prepay(@LoginUser Integer userId, @RequestBody String body){
        //先写死
//        userId=4;
        if(ObjectUtil.isEmpty(userId)){
            return R.badArgument();
        }
        if(ObjectUtil.isEmpty(body)){
            return R.badArgument();
        }
        R r = orderService.prepay(body);
        return r;
    }

}
